package com.phkj.qdh.ui.adapter.teamlawnode

import android.widget.CheckBox
import android.widget.RelativeLayout
import com.phkj.qdh.R
import com.phkj.qdh.ui.dialog.TeamOrLawTreeSelectDialog
import com.phkj.qdh.utils.LogUtil
import com.phkj.qdh.utils.gone
import com.phkj.qdh.utils.node.BaseNode
import com.phkj.qdh.utils.node.BaseNodeProvider
import com.phkj.qdh.utils.node.BaseViewHolder
import com.phkj.qdh.utils.visible
import rxhttp.wrapper.utils.GsonUtil

class TeamTreeHeadProvider(val dialog: TeamOrLawTreeSelectDialog) : BaseNodeProvider() {
    override val itemViewType: Int
        get() = 1
    override val layoutId: Int
        get() = R.layout.item_tree_head

    override fun convert(helper: BaseViewHolder, item: BaseNode) {
        val data = item as TeamSortHeadNode
        val cb = helper.getView<CheckBox>(R.id.cb)
        helper.setText(R.id.tv_name, item.head.name)
        cb.setOnCheckedChangeListener(null)
        cb.isChecked = item.isSelected
        helper.getView<RelativeLayout>(R.id.ll).setOnClickListener {
            dialog.nodeList.forEach { head ->
                head as TeamSortHeadNode
                head.isSelected = false
                head.child?.forEach { child ->
                    child as TeamSortContentNode
                    child.isSelected = false
                }
            }
            item.isSelected = true
            cb.isChecked = item.isSelected
            getAdapter()?.notifyDataSetChanged()
        }
    }
}